package constants

import (
	"jvm/nzpJvm/instructions/base"
	"jvm/nzpJvm/runtime_area"
)

// 将byte类型的常量值入栈其值来自字节码中读出
type BIPUSH struct {
	val int8
}

func (self *BIPUSH) Execute(frame *runtime_area.Frame) {
	i := int32(self.val)
	// 在操作数栈中，byte、short、char、boolean都是当做int值来入栈和出栈。
	frame.OperandStack().PushInt(i)
}
func (self *BIPUSH) FetchOperands(reader *base.BytecodeReader) {
	// 从字节码中读取操作数
	self.val = reader.ReadInt8()
}

// 将short类型的常量值入栈。其值来自字节码中读出
type SIPUSH struct {
	val int16
}

func (self *SIPUSH) Execute(frame *runtime_area.Frame) {
	i := int32(self.val)
	frame.OperandStack().PushInt(i)
}
func (self *SIPUSH) FetchOperands(reader *base.BytecodeReader) {
	// 从字节码中读取操作数
	self.val = reader.ReadInt16()
}
